<template>
  <!-- 我的考勤 -->
  <div id="myAttendance">
    <div class="topBox">
      <div class="left">
        <img :src="require('/public/img/icon9.webp')" alt="" />
        <p class="name">我的考勤</p>
      </div>
      <div class="right">
        <el-date-picker
          v-model="date"
          type="date"
          :clearable="false"
          value-format="YYYY-MM-DD"
          @change="changeDate"
        >
        </el-date-picker>
      </div>
    </div>
    <div class="list">
      <div class="item">
        <div class="left">
          <img :src="require('/public/img/icon_clockIn.webp')" alt="" />
          <div class="line"></div>
        </div>
        <div class="info">
          <div class="infoItem">
            <p>上班</p>
            <p>{{ clockIn.attendanceTime }}</p>
            <p style="color: #f04844" v-if="clockIn.inClockType == 0">未打卡</p>
            <p style="color: #29d094" v-if="clockIn.inClockType == 1">正常</p>
            <p style="color: #f04844" v-if="clockIn.inClockType == 2">迟到</p>
            <p style="color: #f04844" v-if="clockIn.inClockType == 3">早退</p>
            <!-- inClockType上班打卡类型：0未打卡1正常2迟到3早退 -->
          </div>
          <div class="location" v-if="clockIn.address">
            <el-icon class="icon" color="#FF8743" size="14"
              ><el-icon-location
            /></el-icon>
            <p>{{ clockIn.address }}</p>
          </div>
        </div>
      </div>
      <div class="item">
        <div class="left">
          <img :src="require('/public/img/icon_clockIn.webp')" alt="" />
          <div class="line"></div>
        </div>
        <div class="info">
          <div class="infoItem">
            <p>下班</p>
            <p>{{ clockIOut.attendanceTime }}</p>
            <p style="color: #f04844" v-if="clockIOut.inClockType == 0">
              未打卡
            </p>
            <p style="color: #29d094" v-if="clockIOut.inClockType == 1">正常</p>
            <p style="color: #f04844" v-if="clockIOut.inClockType == 2">迟到</p>
            <p style="color: #f04844" v-if="clockIOut.inClockType == 3">早退</p>
            <!-- inClockType上班打卡类型：0未打卡1正常2迟到3早退 -->
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>

export default {
  name: 'myAttendance',
  data () {
    return {
      clockIn: {},//签到数据
      clockIOut: {},//签退数据
      date: this.$TOOL.dateFormat(new Date(), "yyyy-MM-dd")
    }
  },
  mounted () {
    this.getDetail()
  },
  methods: {
    // 获取用某天打卡详情
    async getDetail () {
      let userInfo = this.$TOOL.data.get("USER_INFO")
      let param = {
        adminId: userInfo.userId,
        time: this.date
      }
      let { data } = await this.$API.attendance.getUserClockIn.post(param)
      if (data && data.attendanceChildDTOList) {
        data.attendanceChildDTOList.forEach(item => {
          // 	clockType 签到类型：1签到,2签退
          if (item.clockType == 1) {
            this.clockIn = item
          } else if (item.clockType == 2) {
            this.clockIOut = item
          }
        })
        this.clockIn.attendanceTime ? this.clockIn.attendanceTime = this.clockIn.attendanceTime.slice(10) : this.clockIn.attendanceTime = ''
        this.clockIOut.attendanceTime ? this.clockIOut.attendanceTime = this.clockIOut.attendanceTime.slice(10) : this.clockIOut.attendanceTime = ''

      }



    },
    changeDate () {
      this.getDetail()
    }
  }
}
</script>
<style lang="scss" scoped>
#myAttendance {
  // margin-top: 20px;
  padding: 20px 20px 0 20px;
  background: #ffffff;
  border-radius: 8px;
  .topBox {
    display: flex;
    justify-content: space-between;
    padding-bottom: 20px;
    border-bottom: 1px #eee solid;
  }
  .left {
    display: flex;
    align-items: center;
    .name {
      margin-left: 10px;
      font-size: 16px;
    }
  }
  .right {
    display: flex;
    align-items: center;
    font-size: 14px;
    color: #999;
    cursor: pointer;
    .icon {
      margin-left: 5px;
      font-size: 16px;
    }
  }

  .list {
    margin-top: 20px;
    margin-left: 30px;
  }
  .item {
    display: flex;
    align-items: flex-start;
    font-size: 16px;
    color: #666;
    .left {
      display: flex;
      flex-direction: column;
      align-items: center;
      // margin-top: 2px;
      margin-right: 10px;
    }

    .line {
      width: 1px;
      height: 80px;
      background-color: #bdbaff;
    }
    .info {
      margin-top: -2px;
      .infoItem {
        display: flex;
        align-items: center;
      }
      p {
        margin-right: 5px;
      }
    }
    .location {
      display: flex;
      align-items: center;
      margin-top: 10px;
      font-size: 12px;
      color: #999;
      p {
        margin-left: 5px;
      }
    }
  }
}
</style>